Skip to content

Google sync#600

Merged
rchen152 merged 17 commits into
masterfrom
google_sync
Jun 12, 2020
Merged

Google sync#600
rchen152 merged 17 commits into
masterfrom
google_sync

Conversation

@rchen152

Copy link
Copy Markdown
Contributor

No description provided.

rchen152 and others added 17 commits June 12, 2020 14:08
…notation.

With this change, pytype will report an error for:
  x: str = 0
by default. Erroring on:
  x = 0  # type: str
or
  x: str
  x = 0
will still require the --check-variable-types flag.

PiperOrigin-RevId: 314234094
If options.check_variable_types is set, the following code should fail:

    a: List[int] = []
    a.append("hello")

Also adds some test cases in bugs/mutation.py for TODOs.

PiperOrigin-RevId: 314239043
…den.

Exceptions (treated as ambiguous) are:
- booleans
- numeric types
- classes overriding __bool__ (__nonzero__ in python2)
- classes overriding __len__

Provably empty builtin containers continue to be treated as False.

PiperOrigin-RevId: 314390311
New output format example:

File "third_party/py/pytype/bugs/mutation.py", line 19, in <module>: New container type does not match type annotation [container-type-mismatch]
  Annotation: Dict[str, str] (type parameters Dict[_K, _V])
  Contained types:
    _K: str
    _V: str
  New contained types:
    _K: Union[int, str]
    _V: Union[float, str]

PiperOrigin-RevId: 314422487
Adds a new option, --check-attribute-types, that will make pytype type-check
attribute assignments against annotations, e.g.,

class Foo:
  x: int
  def foo(self):
    self.x = 'hello, world'  # annotation-type-mismatch

I've left a couple of features for future CLs:
* Making annotations take precedence over instance attribute values when
  generating pyi files.
* Handling attribute type comments in __new__ and __init__.

Also puts container mutation checking behind its own flag,
--check-container-types, rather than reusing --check-variable-types. Having
this many flags is rather ugly and redundant, but they'll go away as we release
various things, and they make the release process a bit easier.

PiperOrigin-RevId: 314483072
A corner case where an alias can point to two separate annotated args via
different code paths has been left as a TODO

PiperOrigin-RevId: 314763912
Used in error messages when reporting container type annotation mismatches.

PiperOrigin-RevId: 314791344
Showed up when attempting to analyze
//apps/intelligence/cody/tools/codylab:testit.

PiperOrigin-RevId: 314814112
…biguous.

Allows for the fact that __new__ might be called from a subclass of Foo, and
that checking that we are not in the base class is a common idiom.

PiperOrigin-RevId: 315538618
import is a keyword and therefore is not a valid module name in Python.

PiperOrigin-RevId: 315965683
Prior to this change _get_match_location produced false-positive match
when the name being matched occurred as a prefix of some other imported
name, e.g.

  import foo as f

PiperOrigin-RevId: 316128150
PiperOrigin-RevId: 316139475
With this change,
  v: int = 0
  v = ''
will also be an error. I already cleaned up all new findings introduced by this
change as of about a week ago.

PiperOrigin-RevId: 316170169
For python/typeshed#4224.

We really need a better pyi parser...

PiperOrigin-RevId: 316171517
@rchen152 rchen152 merged commit 284d0f0 into master Jun 12, 2020
@rchen152 rchen152 deleted the google_sync branch June 12, 2020 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants